<?php
/**
 * Created by JetBrains PhpStorm.
 * User: dodasso
 * Date: 7/14/13
 * Time: 8:10 PM
 * To change this template use File | Settings | File Templates.
 */

define('APP_ROOT', realpath(__DIR__ . '/../..'));

require_once(APP_ROOT . '/modules/common/Errors.php');
require_once(APP_ROOT . '/modules/persistance/DBConnector.php');
require_once(APP_ROOT . '/modules/persistance/MovementPersistance.php');

use persistance\DBConnector;
use common\Errors;
use persistance\MovementPersistance;

function testFindMovementByExistingId() {
    $dbconn = new DBConnector();
    $dbconn->connect();

    $p = new MovementPersistance();
    if(!$p->init($dbconn)) {
        print('testFindMovementByExistingId(): FAIL' . PHP_EOL);
        return;
    }

    $rs = $p->findById(1);

    print('testFindMovementByExistingId(): ' .
        (($rs['error'] === Errors::INTEGRAL_ERR_NONE) ? 'OK' : 'FAIL') .
        PHP_EOL);
}

function testFindMovementByNotExistingId() {
    $dbconn = new DBConnector();
    $dbconn->connect();

    $p = new MovementPersistance();
    if(!$p->init($dbconn)) {
        print('testFindMovementByNotExistingId(): FAIL' . PHP_EOL);
        return;
    }

    $rs = $p->findById(9999999999);

    print('testFindMovementByNotExistingId(): ' .
        (($rs['error'] === Errors::INTEGRAL_ERR_PERSISTANCE_NOT_FOUND) ? 'OK' : 'FAIL') .
        PHP_EOL);
}

testFindMovementByExistingId();
testFindMovementByNotExistingId();
